package org.example.design.mediator.test1;

import java.awt.*;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;

/**
 * @author huangshen
 * @version 0
 * @description 表示文本输入框的类
 * @since 2022/2/11 10:22
 */
public class ColleagueTextField extends TextField implements Colleague, TextListener {

    private Mediator mediator;

    public ColleagueTextField(String text, int columns) {
        super(text, columns);
    }

    /**
     * 传递仲裁者示例
     *
     * @param mediator 仲裁者
     */
    @Override
    public void setMediator(Mediator mediator) {
        this.mediator = mediator;
    }

    /**
     * 仲裁者下达的指示 启用为true 停用为false
     *
     * @param enabled 指示
     */
    @Override
    public void setColleagueEnabled(boolean enabled) {
        setEnabled(enabled);
        setBackground(enabled ? Color.white : Color.lightGray);
    }

    /**
     * 文字发生变化时通知Mediator
     * @param e
     */
    @Override
    public void textValueChanged(TextEvent e) {
        mediator.colleagueChanged();
    }
}
